$(document).ready(function() {
	var canvas = $("#gameCanvas");
	var context = canvas.get(0).getContext("2d");
	
	//画布尺寸
	var canvasWidth = canvas.width();
	var canvasHeight = canvas.height();
	
	//游戏设置
	var playGame;
	
	var asterrodis;
	
	var ui = $("#gameUI");
	var uiIntro = $("#gameIntro");
	var uiStats = $("#gameStats");
	var uiComplete = $("#gameComplete");
	var uiPlay = $("#gamePlay");
	var uiReset = $(".gameReset");
	var uiRemaining = $("#gameRemaining");
	var uiScore = $(".gameScore");
	
	//游戏平台
	var platformX;	//平台原点 X
	var platformY;	//平台原点 Y
	var platformOuterRadius;	//外半径（平台区域）
	var platformInnerRadius;	//内半径（放小星星区域）
	
	
	
	
	//重置和启动游戏
	function startGame(){
		uiScore.html("0");
		uiStats.show();
		
		//初始游戏设置
		playGame = false;
		
		platformX = canvasWidth/2;
		platformY = 150;
		platformOuterRadius = 100;
		platformInnerRadius = 75;
		
		var Asteroid = function(x, y, radius, mass, friction){
			this.x = x;
			this.y = y;
			this.radius = radius;
			this.mass = mass;
			this.friction = friction;
			this.vX = 0；
			this.vY = 0;
			this.player = false;
		}
		
		
		//开始动画循环
		animate();
	}
	
	//初始化游戏环境
	function init(){
		uiStats.hide();
		uiComplete.hide();
		
		uiPlay.click(function(e) {
			e.preventDefault();
			uiIntro.hide();
			startGame();
		})
		
		uiReset.click(function(e) {
			e.preventDefault();
			uiComplete.hide();
			startGame();
		})
	}
	
	//动画循环
	function animate(){
		//清除
		context.clearRect(0, 0, canvasWidth, canvasHeight);
		
		context.fillStyle = "rgb(100, 100, 100)";
		context.beginPath();
		context.arc(platformX, platformY, platformOuterRadius, 0, Math.PI*2, true);
		context.fill();
		
		if(playGame){
			//循环
			setTimeout(animate,33);
		}
	}
	init();
})
